package com.a0soft.gphone.aTruffleHog.wnd;
/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 3, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * Copyright(C) 2011 
 *   Sam Lu <ysl.sam.lu (at) gmail.com>
 *
 */

import com.a0soft.gphone.aTruffleHog.R;
import com.a0soft.gphone.aTruffleHog.gio.ui.BaseActivity;
import com.a0soft.gphone.aTruffleHog.util.aDebug;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class MainWnd extends BaseActivity {
	private Handler m_handler;
	
	private static final int STEP_FIRST_RUN = 1;
	private static final int STEP_SHOW_NEW_FEATURES = 2;
	private static final int STEP_SHOW_TOP_WND = 3;
	
	private static final int MSG_SHOW_TOP_WND = 100;
	private static final int MSG_EXIT = 101;
	
	private static final String LOG_TAG = MainWnd.class.getSimpleName();
	
	////////////////////////////////////////////
    @Override public void 
    onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.main_wnd);
        
        m_handler = new Handler() {
			@Override public void 
			handleMessage(Message msg)
            {
				if (msg.what == MSG_SHOW_TOP_WND) {
					Intent it = new Intent(MainWnd.this, DashboardWnd.class);
					startActivity(it);
				}
				finish();
            }        	
        };
        
        _CheckBeforeInvokingTopWnd(STEP_FIRST_RUN);
    }
    
    private void
	_CheckBeforeInvokingTopWnd(int nStep)
	{
    	if (aDebug.ENABLED)
    		aDebug.d(LOG_TAG, "_CheckBeforeInvokingTopWnd(): step=" + nStep);
    	
		switch (nStep) {
		case STEP_FIRST_RUN:
			if (_CheckIfFirstRun())
				return;
			
			_CheckBeforeInvokingTopWnd(STEP_SHOW_NEW_FEATURES);
			break;
			
		case STEP_SHOW_NEW_FEATURES:
			if (_CheckIfShowNewFeatures())
				return;
			
			_CheckBeforeInvokingTopWnd(STEP_SHOW_TOP_WND);
			break;
			
		case STEP_SHOW_TOP_WND:
			_InvokeTopWnd();
			break;
			
		default:
			if (aDebug.ENABLED)
				aDebug.e(LOG_TAG, "unknown step: " + nStep);
			
			_InvokeTopWnd();
			break;
		}
	}
    
    private boolean
    _CheckIfFirstRun()
    { 
    	return false;
    }
    
    private boolean
    _CheckIfShowNewFeatures()
    { 
    	return false;
    }
    
    private void
	_InvokeTopWnd()
	{
    	m_handler.sendEmptyMessageDelayed(MSG_SHOW_TOP_WND, 100L);
	}
    
    @SuppressWarnings("unused") private void
	_Exit()
	{
    	m_handler.sendEmptyMessageDelayed(MSG_EXIT, 100L);
	}
}